package com.chinemit.cui.components.text
{
	import flash.display.DisplayObject;
	import flash.events.Event;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	import flash.utils.clearTimeout;
	import flash.utils.setTimeout;
	
	public class WordEffect extends TextField
	{
		private var _txt:String ; 
		private var _timeoutId:int ;
		private var _delay:int ;
		public var color:uint = 0xffcc00 ;
		
		public function WordEffect(container:DisplayObject, txt:String , delay:int = 0 )
		{
			super();
			this.mouseEnabled = this.selectable = false ;
			this.width = container.width/2 ;
			this._txt = txt ;
			this._delay = delay ;
			this.visible = false ;
			this.multiline = false ;
			this.wordWrap = false ;
			this.addEventListener(Event.ADDED_TO_STAGE , addToStageHandler );
		}
		
		private function addToStageHandler( event:Event):void
		{
			event.stopPropagation();
			this.removeEventListener(Event.ADDED_TO_STAGE , addToStageHandler );
			init();
			_timeoutId = setTimeout( destoryAnimation , _delay );
		}
		
		protected function init():void
		{
			var format:TextFormat = new TextFormat("Arial",16,color,true);
			format.align = TextFieldAutoSize.CENTER ;
			this.defaultTextFormat = format ;
			this.htmlText = _txt;
//			TweenMax.to(this, 0 , {dropShadowFilter:{color:0x000000, alpha:1, blurX:2, blurY:2, strength:8}});
		}
		
		protected function destoryAnimation():void
		{
			this.visible = true;
//			TweenLite.to( this, 2 , { alpha:0 , y:this.y-120 , onComplete:tweenCom} );
		}
		
		private function tweenCom():void
		{
			if(this.parent){
				this.parent.removeChild( this );
			}
			clearTimeout( _timeoutId );
		}
	}
}